﻿namespace com.stifel.BranchMgmt
{
    using System.Collections.Generic;
    using System.Text;

    using com.stifel.BranchMgmtDao;

    using Microsoft.SharePoint;

    public partial class BranchMgmtViewUserControl
    {
        #region Fields

        List<uiPersonnel_Data> _uiPersonnel_Data_List;

        #endregion Fields

        #region Properties

        List<uiPersonnel_Data> uiPersonnel_Data_List
        {
            get
            {
                if ( _uiPersonnel_Data_List == null )
                    _uiPersonnel_Data_List = new List<uiPersonnel_Data>( );
                return _uiPersonnel_Data_List;
            }
            set
            {
                _uiPersonnel_Data_List = value;
            }
        }

        #endregion Properties

        #region Methods

        void loadPersonnel( int branchId )
        {
            StifelBranchPersonnelDao dao = new StifelBranchPersonnelDao( SPContext.Current.Web.Url );
            List<StifelBranchPersonnel> l = dao.GetByBranchLocation( branchId );
            foreach ( StifelBranchPersonnel o in l )
                uiPersonnel_Data_List.Add( new uiPersonnel_Data( o ) );
            uiPersonnel_Repeater.DataSource = uiPersonnel_Data_List;
            uiPersonnel_Repeater.DataBind( );
        }

        #endregion Methods

        #region Nested Types

        protected class uiPersonnel_Data
        {
            #region Constructors

            public uiPersonnel_Data( StifelBranchPersonnel value )
            {
                Name = string.Format( "{0}, {1}", value.Title, value.PersonnelName );
                Type = value.PersonnelTypeId.HasValue ? value.PersonnelTypeTitle : string.Empty;
                Note = value.PersonnelNotes;
                StringBuilder sb = new StringBuilder( );
                if ( !string.IsNullOrEmpty( value.TelephoneNumber ) )
                    sb.AppendFormat( "{0}\t", value.TelephoneNumber );
                if ( !string.IsNullOrEmpty( value.AlternateTelephone ) )
                    sb.AppendFormat( "{0}\t", value.AlternateTelephone );
                if ( !string.IsNullOrEmpty( value.FaxNumber ) )
                    sb.AppendFormat( "fax: {0}", value.FaxNumber );
                string s = sb.ToString( ).Trim( '\t' ).Replace( "\t", "<br/>" );
                sb = null;
                TelephoneFax = s;
            }

            #endregion Constructors

            #region Properties

            public string Name
            {
                get;
                set;
            }

            public string Note
            {
                get;
                set;
            }

            public string TelephoneFax
            {
                get;
                set;
            }

            public string Type
            {
                get;
                set;
            }

            public string value
            {
                get;
                set;
            }

            #endregion Properties
        }

        #endregion Nested Types
    }
}